package com.admin.business.background.venusOaWarning;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 员工历史警示表
 * @create: 2023-11-06 17:01:17
 **/
@Service("venusOaWarningService")
@Slf4j
public class VenusOaWarningService{

    @Resource
    VenusOaWarningDao venusOaWarningDao;




    @OpenApi
    public Return addVenusOaWarning(CDO cdoRequest){

        Long   org_id        = cdoRequest.getLong("org_id");          //公司id
        Long   pro_id        = cdoRequest.getLong("pro_id");          //项目id
        Long   dept_id       = cdoRequest.getLong("dept_id");         //部门id
        Long   post_id       = cdoRequest.getLong("post_id");         //岗位id    //能传最好
        Long   employee_id   = cdoRequest.getLong("employee_id");     //员工id
        Long   user_id       = cdoRequest.getLong("user_id");         //被添加人
        //校验
        if (org_id==null){
            if (pro_id==null){
                return Return.valueOf(400,"公司项目不可都为空");
            }else{//通过项目查找公司
                String orgIdByProId = venusOaWarningDao.getOrgIdByProId(pro_id.toString());
                org_id = Long.parseLong(orgIdByProId);
                cdoRequest.set("org_id",org_id);
            }
        }
        if (user_id==null){
            if (employee_id==null){
                return Return.valueOf(400,"参数异常");
            }
        }
        //通过公司 或者项目 和user_id 获取员工信息
        CDO cdo = new CDO();
        if (pro_id!=null){
            cdo.set("pro_id",pro_id);
        }else {
            cdo.set("org_id",org_id);
        }
        cdo.set("post_id",post_id);
        cdo.set("user_id",user_id);
        cdo.set("employee_id",employee_id);
        CDO employee = venusOaWarningDao.getEmployeeIdByCdo(cdo);
        if (employee!=null){
            if (employee_id==null){//获取员工employee_id
                employee_id=employee.getLong("employee_id");
                cdoRequest.set("employee_id",employee_id);
            }
            if (user_id==null){//获取员工user_id
                user_id=employee.getLong("sys_user_id");
                cdoRequest.set("user_id",user_id);
            }
            if (dept_id==null){//获取部门
                dept_id = employee.getLong("employee_org_dept_id");
                cdoRequest.set("dept_id",dept_id);
            }
            if (post_id==null){//获取岗位
                post_id = employee.getLong("employee_org_post_id");
                cdoRequest.set("post_id",post_id);
            }
        }
        if (employee_id==null){
            return Return.valueOf(400,"参数异常");
        }
        venusOaWarningDao.addVenusOaWarning(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }



}
